#include "DataSave.h"
#include <string.h>
#include "Common.h"
#include "Parameters.h"
#include "bsp.h"

#include "usart.h"
#include "userconfig.h"
#include "w25qxx.h"

void Param_Init(void) {
    if (Sys_Base.para.wMagic != FLASH_MAGIC) {   // 恢复默认参数
        Sys_Base.para.wMagic     = FLASH_MAGIC;
        Sys_Base.para.reset      = NORMAL_MODE;
        Sys_Base.para.slave_id   = 1;
        Sys_Base.para.type       = 0;
        Sys_Base.para.mod_num    = 0;
        Sys_Base.para.work_state = STA_OFF;
        SPI_Flash_Write((INT8U*) &Sys_Base.para.wMagic, para_data_addr, sizeof(Sys_Base.para));
    }
    if (Sys_Base.para.reset <= 0 || Sys_Base.para.reset > 1) {
        Sys_Base.para.reset = 0;
    }
    if (Sys_Base.para.slave_id <= 2 || Sys_Base.para.slave_id > 2) {
        Sys_Base.para.slave_id = 2;
    }
    if (Sys_Base.para.type < 1 || Sys_Base.para.type > 1) {
        Sys_Base.para.type = 1;
    }
    if (Sys_Base.para.mod_num <= 0 || Sys_Base.para.mod_num > 2) {
        Sys_Base.para.mod_num = 0;
    }
    if (Sys_Base.para.work_state <= 0 || Sys_Base.para.work_state > 1) {
        Sys_Base.para.work_state = 0;
    }
}
